#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time

from core.exploit.submit_flag import *
from core.exploit.get_flag import *

token = "DqSXgARhK0brh2im8plcH4EdvluS2KmW8MpJCb0oeWQJoSYBrnLLdDtqzAbd78nAbZP9wFBjFEb"

def exploit(host, port):
    flag = get_flag(host, port)
    submit_flag(flag, token)

def exploit_all():
    with open("targets") as f:
        for line in f:
            host = line.split(":")[0]
            port = int(line.split(":")[1])
            print "[+] Exploiting : %s:%d" % (host, port)
            exploit(host, port)

def main():
    print "[+] Starting attack framework..."
    round_time = 60 * 5
    print "[+] Round time : %s seconds..." % (round_time)
    wait_time = round_time / 2
    print "[+] Wait time : %s seconds..." % (wait_time)
    while True:
        exploit_all()
        print "[+] This round is finished , waiting for the next round..."
        for i in range(wait_time):
            print "[+] The next attack is %d seconds later..." % (wait_time - i)
            time.sleep(1)

if __name__ == "__main__":
    main()
